// pages/service/index.js

const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    urlService: app.urlService,
    contentH: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var sysInfo = wx.getSystemInfoSync();
    var winHeight = sysInfo.windowHeight;
    var that = this;
      that.setData({ 
        contentH: winHeight
      })
    that.bindServices();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  bindServices:function(){
    var that = this;
    wx.request({
      url: this.data.urlService + '/api/Service/GetPageList',
      method: "POST",
      data: {
        page: 1,
        limit: 30
      },
      dataType: "JSON",
      header: {
        'content-type': 'application/json',
        'Authorization': "Bearer " + app.token
      },
      success: function (res) {
        var data = JSON.parse(res.data);
        if (data.status) {
          that.setData({
            serviceList: data.data.list
          })
        }
        wx.createSelectorQuery().select('.list-item').boundingClientRect().exec(function (hres) {
          that.setData({
            goodHeight: hres[0].width
          })
        });
      }
    })
  },

  goDetail:function(e){
    if (app.userInfo == null) {
      wx.showModal({
        title:"登录提示",
        content:"后续操作需要登录才能继续！",
        success:function(res){
          if (res.confirm) {
            wx.navigateTo({
              url: "../login/index"
            })
          } 
        }
      })
      return;
    }
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "../servicedetail/index?id=" + id + ""
    })
  }

})